package com.yanxibao.controller;

import com.yanxibao.bean.Collection;
import com.yanxibao.common.Result;
import com.yanxibao.dto.PageQueryDTO;
import com.yanxibao.service.CollectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 收藏;(_collection)表控制层
 *
 * @author kongke
 * @date 2023/11/16
 */

@Api(tags = "收藏对象功能接口")
@RestController
@CrossOrigin
@RequestMapping("/Collection")
public class CollectionController {

    @Resource
    private CollectionService collectionService;

    /**
     * 通过ID查询单条数据
     */
    @ApiOperation("通过ID查询单条数据")
    @GetMapping("/getById/{colId}")
    @ResponseBody
    public Result<Collection> queryById(@PathVariable Integer colId) {
        return collectionService.queryById(colId);
    }


    /**
     * 查询用户的所有收藏
     * 分页
     */
    @ApiOperation("查询用户收藏")
    @GetMapping("/getCol")
    public Result<PageQueryDTO<Collection>> getCol(@RequestBody Collection collection
            , @RequestParam("current") Integer current, @RequestParam("size") Integer size) {
        return collectionService.pageQuery(collection, current, size);
    }

    /**
     * 新增数据
     *
     * @param Collection 实例对象
     * @return 实例对象
     */
    @ApiOperation("新增数据")
    @PostMapping("/add")
    public Result<Collection> add(@RequestBody Collection Collection) {
        return collectionService.insert(Collection);
    }

    /**
     * 通过主键删除数据
     *
     * @return 是否成功
     */
    @ApiOperation("通过主键删除数据")
    @DeleteMapping("/del/{colId}")
    public Result<Boolean> deleteById(@PathVariable Integer colId) {
        return collectionService.deleteById(colId);
    }


    @ApiOperation("查询是否收藏")
    @GetMapping("/isCol")
    public Result<Boolean> isCol(@RequestParam("userId") String userId, @RequestParam("umId") Integer umId) {
        return collectionService.isCol(userId, umId);
    }
}